Micron Document
Livres et Wikis | Archives | Info


Java bytecode
part 3/9 Β· 28.3 KB total
layout: Wide Β· Narrow Β· Centered
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
counted as two units in the depth of the stack).cite-ref-jvm-5-3[5]

Instruction set

Each bytecode is composed of one byte that represents the opcode, along
with zero or more bytes for operands.cite-ref-jvm-5-4[5]

Of the 256 possible byte-long opcodes, as of 2015, 202 are in use
(~79%), 51 are reserved for future use (~20%), and 3 instructions (~1%)
are permanently reserved for JVM implementations to use.cite-ref-jvm-5-5[5] Two of these
(impdep1 and impdep2) are to provide traps for implementation-specific
software and hardware, respectively. The third is used for debuggers to
implement breakpoints.

Instructions fall into a number of broad groups:

β€’ Load and store (e.g. aload_0, istore)
β€’ Arithmetic and logic (e.g. ladd, fcmpl)
β€’ Type conversion (e.g. i2b, d2i)
β€’ Object creation and manipulation (new, putfield)
β€’ Operand stack management (e.g. swap, dup2)
β€’ Control transfer (e.g. ifeq, goto)
β€’ Method invocation and return (e.g. invokespecial, areturn)

There are also a few instructions for a number of more specialized tasks
such as exception throwing, synchronization, etc.

Many instructions have prefixes and/or suffixes referring to the types
of operands they operate on.cite-ref-jvm-5-6[5] These are as follows:

| Prefix/suffix | Operand type |
|---|---|
| i | integer |
| l | long |
| s | short |
| b | byte |
| c | character |
| f | float |
| d | double |
| a | reference |

For example, iadd will add two integers, while dadd will add two
doubles. The const, load, and store instructions may also take a suffix
of the form _n, where n is a number from 0–3 for load and store. The
maximum n for const differs by type.

The const instructions push a value of the specified type onto the
stack. For example, iconst_5 will push an integer (32 bit value) with
the value 5 onto the stack, while dconst_1 will push a double (64 bit
floating point value) with the value 1 onto the stack. There is also an
aconst_null, which pushes a null reference. The n for the load and store
instructions specifies the index in the local variable array to load
from or store to. The aload_0 instruction pushes the object in local
variable 0 onto the stack (this is usually the this object). istore_1
stores the integer on the top of the stack into local variable 1. For
local variables beyond 3 the suffix is dropped and operands must be
used.

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────